#!/bin/bash

cd /etc/sysconfig/network-scripts/
interface=`eval echo $(ip link | grep -v lo | head -n1 | cut  -d: -f2)`

sed -i 's/dhcp/static/' ifcfg-${interface}
GATEWAY=`ip route show | head -n 1 | egrep -o "([0-9]{1,3}.){3}[0-9]"`
pre=${GATEWAY%.*}
suf=${GATEWAY##*.}

while true
do
  num=`expr $(date +%N) % $[254 - 2  + 1] + 2`
  if [[ $num != $suf ]];then
    break
  fi
done
cat >> ifcfg-${interface}<<EOF
IPADDR=${pre}.${num}
PREFIX=24
GATEWAY=${GATEWAY} 
DNS1=114.114.114.114
EOF